from pythonping import ping

if __name__ == "__main__":
    # url = "www.baidu.com"
    url = "111.222.111.010"
    ret = ping(url, count=4, timeout=4)
    print("网络是否可达:", ret.success())
    print(f"网络延迟: {ret.rtt_avg_ms} ms")
    print("ping 结果:", ret)

""" 可达到网络
网络是否可达: True
网络延迟: 9.45
"""

""" 不可到达网络
网络是否可达: False
网络延迟: 4000.0
"""